//
//  SetStrokeColorCommand.m
//  Test
//
//  Created by 杨德龙 on 2017/11/24.
//  Copyright © 2017年 ___杨德龙___. All rights reserved.
//

#import "SetStrokeColorCommand.h"
#import "CoordinatingController.h"
#import "CanvasViewController.h"

@implementation SetStrokeColorCommand
@synthesize delegate = delegate_,RGBValuesProvider = RGBValuesProvider_,postColorUpdateProvider = postColorUpdateProvider_;

- (void)execute
{
    CGFloat redValue = 0.0;
    CGFloat greenValue = 0.0;
    CGFloat blueValue = 0.0;
    //  从代理中获取  RGB 值
    if (delegate_) {
        [delegate_ command:self didRequestColorComponetsForRed:&redValue green:&greenValue blue:&blueValue];
    }
    
    if (RGBValuesProvider_) {
        RGBValuesProvider_(&redValue,&greenValue,&blueValue);
    }
    
    // 根据RGB 值创建一个 Color 对象
    UIColor *color = [UIColor colorWithRed:redValue green:greenValue blue:blueValue alpha:1.0];
    
    // 设置  这个 color
    CoordinatingController *coordinator = [CoordinatingController sharedInstance];
    CanvasViewController *controller = [coordinator canvasViewController];
    [controller  setStrokeColor:color];
    //
    if (delegate_) {
        [delegate_ command:self didFinishColorUpdateWithColor:color];
    }
    
    //
    if (postColorUpdateProvider_) {
        postColorUpdateProvider_(color);
    }
}

@end





























































































